package com.minimalist.common.entity.basic.vo.user;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.NullSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.minimalist.common.config.convert.LongArrJsonSerializer;
import com.minimalist.common.config.swagger.SchemaEnum;
import com.minimalist.common.entity.basic.enums.StatusEnum;
import com.minimalist.common.entity.basic.enums.UserEnum;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author 11987
 */

@Schema(name = "用户管理实体")
public class UserVO implements Serializable{

    @Serial
    private static final long serialVersionUID = 1L;

    @JsonSerialize(using = ToStringSerializer.class)
    @NotNull(message = "用户ID不能为空", groups = {Update.class})
    @Schema(name = "userId", description = "用户ID", type = "string")
    private Long userId;

    public Long getUserId(){
        return userId;
    }

    public void setUserId(Long userId){
        this.userId = userId;
    }

    @NotBlank(message = "用户账号不能为空", groups = {Add.class, Update.class})
    @Schema(name = "username", description = "用户账号", type = "string")
    private String username;

    public String getUsername(){
        return username;
    }

    public void setUsername(String username){
        this.username = username;
    }

    @JsonSerialize(using = NullSerializer.class)
    @Schema(name = "password", description = "密码", type = "string")
    private String password;

    public String getPassword(){
        return password;
    }

    public void setPassword(String password){
        this.password = password;
    }

    @NotBlank(message = "用户昵称不能为空", groups = {Add.class, Update.class})
    @Schema(name = "nickname", description = "用户昵称", type = "string")
    private String nickname;

    public String getNickname(){
        return nickname;
    }

    public void setNickname(String nickname){
        this.nickname = nickname;
    }

    @NotBlank(message = "用户真实姓名不能为空", groups = {Add.class, Update.class})
    @Schema(name = "userRealName", description = "用户真实姓名", type = "string")
    private String userRealName;

    public String getUserRealName(){
        return userRealName;
    }

    public void setUserRealName(String userRealName){
        this.userRealName = userRealName;
    }

    @NotBlank(message = "手机号不能为空", groups = {Add.class, Update.class})
    @Schema(name = "phone", description = "手机号码", type = "string")
    private String phone;

    public String getPhone(){
        return phone;
    }

    public void setPhone(String phone){
        this.phone = phone;
    }

    @Schema(name = "email", description = "用户邮箱，可为空", type = "string")
    private String email;

    public String getEmail(){
        return email;
    }

    public void setEmail(String email){
        this.email = email;
    }

    @NotNull(message = "用户性别不能为空", groups = {Add.class, Update.class})
    @SchemaEnum(implementation = UserEnum.UserSex.class)
    @Schema(name = "userSex", description = "用户性别", type = "integer")
    private Integer userSex;

    public Integer getUserSex(){
        return userSex;
    }

    public void setUserSex(Integer userSex){
        this.userSex = userSex;
    }

    @Schema(name = "userAvatar", description = "用户头像base64编码", type = "string")
    private String userAvatar;

    public String getUserAvatar(){
        return userAvatar;
    }

    public void setUserAvatar(String userAvatar){
        this.userAvatar = userAvatar;
    }

    @Schema(name = "remark", description = "备注", type = "string")
    private String remark;

    public String getRemark(){
        return remark;
    }

    public void setRemark(String remark){
        this.remark = remark;
    }

    @NotNull(message = "用户状态不能为空", groups = {Update.class})
    @SchemaEnum(implementation = StatusEnum.class)
    @Schema(name = "status", description = "用户状态", type = "integer")
    private Integer status;

    public Integer getStatus(){
        return status;
    }

    public void setStatus(Integer status){
        this.status = status;
    }

    @JsonSerialize(using = ToStringSerializer.class)
    @Schema(name = "tenantId", description = "租户编号", type = "string")
    private Long tenantId;

    public Long getTenantId(){
        return tenantId;
    }

    public void setTenantId(Long tenantId){
        this.tenantId = tenantId;
    }

    @JsonSerialize(using = ToStringSerializer.class)
    @Schema(name = "deptId", description = "部门ID", type = "string")
    private Long deptId;

    public Long getDeptId(){
        return deptId;
    }

    public void setDeptId(Long deptId){
        this.deptId = deptId;
    }

    @JsonSerialize(using = LongArrJsonSerializer.class)
    @NotEmpty(message = "角色不能为空", groups = {Add.class, Update.class})
    @Schema(name = "roles", description = "角色ID集合", type = "array")
    private Set<Long> roleIds;

    public Set<Long> getRoleIds(){
        return roleIds;
    }

    public void setRoleIds(Set<Long> roleIds){
        this.roleIds = roleIds;
    }

    @JsonSerialize(using = LongArrJsonSerializer.class)
    @Schema(name = "postIds", description = "岗位ID集合", type = "array")
    private Set<Long> postIds;

    public Set<Long> getPostIds(){
        return postIds;
    }

    public void setPostIds(Set<Long> postIds){
        this.postIds = postIds;
    }

    @JsonSerialize(using = LongArrJsonSerializer.class)
    @Schema(name = "deptIds", description = "部门ID集合", type = "array")
    private Set<Long> deptIds;

    public Set<Long> getDeptIds(){
        return deptIds;
    }

    public void setDeptIds(Set<Long> deptIds){
        this.deptIds = deptIds;
    }

    @Schema(name = "checkedPermIds", description = "用户部门编码集合，全勾选的节点", type = "array")
    private List<String> checkedDeptIds;

    public List<String> getCheckedDeptIds(){
        return checkedDeptIds;
    }

    public void setCheckedDeptIds(List<String> checkedDeptIds){
        this.checkedDeptIds = checkedDeptIds;
    }

    @Override
    public boolean equals(Object o){
        if (this == o){
            return true;
        }
        if (o == null || getClass() != o.getClass()){
            return false;
        }
        UserVO userVO = (UserVO) o;
        return Objects.equals(userId, userVO.userId) &&
                Objects.equals(username, userVO.username) &&
                Objects.equals(password, userVO.password) &&
                Objects.equals(nickname, userVO.nickname) &&
                Objects.equals(userRealName, userVO.userRealName) &&
                Objects.equals(phone, userVO.phone) &&
                Objects.equals(email, userVO.email) &&
                Objects.equals(userSex, userVO.userSex) &&
                Objects.equals(userAvatar, userVO.userAvatar) &&
                Objects.equals(remark, userVO.remark) &&
                Objects.equals(status, userVO.status) &&
                Objects.equals(tenantId, userVO.tenantId) &&
                Objects.equals(roleIds, userVO.roleIds) &&
                Objects.equals(postIds, userVO.postIds) &&
                Objects.equals(deptIds, userVO.deptIds) &&
                Objects.equals(checkedDeptIds, userVO.checkedDeptIds);
    }

    @Override
    public int hashCode(){
        return Objects.hash(userId, username, password, nickname, userRealName, phone, email, userSex, userAvatar, remark, status, tenantId, roleIds, postIds, deptIds, checkedDeptIds);
    }

    @Override
    public String toString(){
        return "UserVO{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", nickname='" + nickname + '\'' +
                ", userRealName='" + userRealName + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", userSex=" + userSex +
                ", userAvatar='" + userAvatar + '\'' +
                ", remark='" + remark + '\'' +
                ", status=" + status +
                ", tenantId=" + tenantId +
                ", roleIds=" + roleIds +
                ", postIds=" + postIds +
                ", deptIds=" + deptIds +
                ", checkedDeptIds=" + checkedDeptIds +
                '}';
    }
}
